<?php

class JSONDataParser extends DataParser {

    public function parseData($data) {
        $arrs = json_decode($data);
        $keyword = $this->getOption('keywords');
        $keywords = explode(",", $keyword);
        $direction = $this->getOption('direction');
        foreach ($arrs as $array) {
            $arr = get_object_vars($array);
            if (isset($keyword) && isset($arr['ORG_NAME']) && isset($direction)) {
                if ($direction == 0) {
                    foreach ($keywords as $key) {
                        if (!strpos($arr['ORG_NAME'], $key)) {
                            $str[] = $arr;
                        }
                    }
                } else if ($direction == 1) {
                    foreach ($keywords as $key) {
                        if (strpos($arr['ORG_NAME'], $key)) {
                            $str[] = $arr;
                        }
                    }
                }
            } else {
                $str[] = $arr;
            }
        }
        $this->setTotalItems(count($str));
        return $str;
    }
}
